import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
// 引入 axios
import axios from 'axios'
// 导入Tree-Table
import TreeTable from 'vue-table-with-tree-grid'
// 导入vue-quill-editor 富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
// 导入vue-quill-editor 富文本编辑器样式
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
// 将富文本注册为全局可用
Vue.use(VueQuillEditor)
// 把TreeTable 注册为全局组件
Vue.component('tree-table', TreeTable)
// 设置服务器的基准路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 设置请求拦截 给请求头添加验证的字段 Authorization = token
axios.interceptors.request.use(config => {
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
// 绑定到Vue的原型上 这样就能直接通过 this.$http 获取axios
Vue.prototype.$http = axios

Vue.config.productionTip = false

// 注册全局的过滤器
Vue.filter('dateFormat', function(val) {
  const dd = new Date()
  const y = dd.getFullYear()
  const m = (dd.getMonth() + 1 + '').padStart(2, '0')
  const d = (dd.getDate() + '').padStart(2, '0')
  const hh = (dd.getHours() + '').padStart(2, '0')
  const mm = (dd.getMinutes() + '').padStart(2, '0')
  const ss = (dd.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
